/*package site.jlopen.assets.config.interceptor;

import java.io.PrintWriter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import site.jlopen.assets.config.ThreadAuthUser;
import site.jlopen.entity.BaseResponse;
import site.jlopen.utils.StringUtil;

@Configuration
public class ApiInterceptor implements HandlerInterceptor {
	private static Logger logger = LoggerFactory.getLogger(ApiInterceptor.class);

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		String token = request.getHeader("sign");
		Long apiId = ThreadAuthUser.getUserId();
		// logger.info("apiId：{}", apiId);
		if(StringUtil.isEmpty(token)) {
			resp(response, 401, "Not AUTH");
			return false;
		}
		if(StringUtil.isEmpty(apiId)) {
			resp(response, 401, "Not AUTH User");
			return false;
		}
		return true;
	}

	private void resp(HttpServletResponse response, int status, String msg) throws Exception {
		response.setContentType("application/json");
		try (PrintWriter out = response.getWriter()) {
			BaseResponse<String> res = new BaseResponse<String>(status, msg);
			out.write(new ObjectMapper().writeValueAsString(res));
		} catch (JsonProcessingException e) {
			logger.error("json 解析异常：{}", e);
		}
	}
	
	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		if (response.getStatus() != HttpStatus.OK.value()) {
			response.setContentType("application/json");
			response.setCharacterEncoding("UTF-8");
			BaseResponse<String> res = new BaseResponse<String>(response.getStatus(), "请求异常");
			response.getWriter().write(new ObjectMapper().writeValueAsString(res));
		}
	}
}
*/